package com.sd.repay.service.impl;

import com.sd.repay.dao.BaseDao;
import com.sd.repay.service.RankService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author twoman
 * @Description: 商户等级服务类
 * @date 2017年10月25日
 */
@Service
public class RankServiceImpl implements RankService {

    private static Logger log = LoggerFactory.getLogger(RankServiceImpl.class);

    @Autowired
    private BaseDao baseDao;

    /**
     * 根据oem、code、service获取等级值
     *
     * @param oemTypee
     * @param rankCode
     * @param rankService
     * @return
     * @throws Exception
     */
    @Override
    public String getRankConfigByOemAndCodeAndService(String oemTypee, String rankCode, String rankService) throws Exception {

        String sql = " SELECT * FROM t_rank_config WHERE oem_type = ? AND rank_code = ? AND rank_service = ? ";
        Map<String, Object> map = baseDao.findFirst(sql, new Object[]{oemTypee, rankCode, rankService});
        return (map == null || map.isEmpty()) ? null : String.valueOf(map.get("rank_value"));
    }


    @Override
    public Map<String, Object> getRankConfigByOemAndCode(String oemType, String rankCode) throws Exception {
        String sql = " SELECT rank_service rankService, rank_value rankValue FROM t_rank_config WHERE oem_type = ? AND rank_code = ? ";
        List<Map<String, Object>> queryList = baseDao.findList(sql, new Object[]{oemType, rankCode});
        Map<String, Object> resMap = new HashMap<>();

        for (Map<String, Object> origMap : queryList) {
            resMap.put(String.valueOf(origMap.get("rankService")), origMap.get("rankValue"));
        }
        return resMap;
    }
}